<template>
	<view class="message-list">
		<!-- 列表数据 -->
		<com-scroller ref="refList" :list="messageList" :listKey="listKey" :reload="reload" :queryModel="queryModel"  @loaded="getList"  @getMore=getMore>
			<uni-list>
				<uni-list-chat @click="navtoDeatils(item.id)" v-for="(item, index) in messageList" :key="item.id" :title="item.mid" :avatar="item.pic" :time="item.addtime" :clickable="true" :note="item.content"></uni-list-chat>
			</uni-list>
		</com-scroller>
	</view>
</template>

<script>
	import { mapState } from 'vuex'
	export default {
		computed: {
			...mapState(['uid'])
		},
		data() {
			return {
				fetch: '', // 列表接口
				listKey: 'messageList', // 列表请求返回的字段key
				queryModel: { // 请求列表参数
				},
				isnomore: false,
				page: 0,
				reload: false,
				messageList: [], // 列表数据
			};
		},
		created() {
			this.getList()
		},
		onReachBottom() {
		  this.getMore()
		},
		methods: {
			// 获取列表数据
			getList() {
				let that = this;
				this.page = 0
				this.reload = true;
				that.http.httpRequest('/notice/messageList','post',{uid: this.uid, page: this.page}).then(res => {
					this.messageList = res.data.data
				}) 	
				this.reload = false;
			},
			// 跳转到详情页
			navtoDeatils (id) {
				uni.navigateTo({
					url: '../message/messageDetail/messageDetail?id=' + id
				})
			},
			// 加载更多
			async getMore () {
			  this.page ++
			  const res = await this.http.httpRequest('/notice/messageList','post',{uid: this.uid, page: this.page})
			 if (res.data.data.length ==0) {
				 this.isnomore = true
			 	this.$u.toast('没有更多数据了')
			 	return
			 }
			  this.messageList = [...this.messageList, ...res.data.data]
			}
		},
	};
</script>

<style lang="scss" scoped>
	.message-list {
		height: 100%;
	}
</style>